import { View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import GoodsItem from '@/components/GoodsItem';
import EmptyContent from '@/components/EmptyContent';
import './index.scss';

export default function ({ productList }) {
  const onHandle = (id: number) => {
    Taro.navigateTo({
      url: '/pages/goods/detail/index?id=' + id,
    });
  };

  return (
    <View className="search-container-product">
      {productList.length === 0 ? (
        <EmptyContent title="没有找到相关的产品" />
      ) : (
        <View className="product-list">
          {productList.map((goods) => {
            return (
              <GoodsItem
                type="search"
                key={goods.id}
                goodsInfo={goods}
                onHandle={() => onHandle(goods.goods_id)}
              />
            );
          })}
        </View>
      )}
    </View>
  );
}
